/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.customer.core.repository.entity.CustomerLogEntity;
import info.peigen.hotpot.business.customer.manage.convertor.CustomerLogManageConvertor;
import info.peigen.hotpot.business.customer.manage.form.CustomerLogManageCreateForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerLogManageEditForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerLogManageSearchForm;
import info.peigen.hotpot.business.customer.manage.info.CustomerLogManageInfo;
import info.peigen.hotpot.business.customer.manage.repository.service.CustomerLogManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(CustomerLogManageService)</b>
 * 管理后台 "客户登录日志" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-09-08
 */
@SuppressWarnings("unused")
@Component
public class CustomerLogManageService {
    @Inject
    CustomerLogManageRepository customerLogManageRepository;

    public PageResult<CustomerLogManageInfo> page(CustomerLogManageSearchForm form) {
        LambdaQuery<CustomerLogEntity> lambdaQuery = customerLogManageRepository.getMapper().createLambdaQuery()
                .andLike(CustomerLogEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true));

        return customerLogManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, CustomerLogManageConvertor::convertToInfo);
    }

    public void create(CustomerLogManageCreateForm form) {
        CustomerLogEntity entity = BeanUtil.copyProperties(form, CustomerLogEntity.class);
        customerLogManageRepository.save(entity);
    }

    public void edit(CustomerLogManageEditForm form) {
        CustomerLogEntity entity = BeanUtil.copyProperties(form, CustomerLogEntity.class);
        customerLogManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        customerLogManageRepository.delete(id);
    }
}